<html>
<head><meta charset="utf-8"><title>Why lint on &amp;Option&lt;&amp;T&gt; but not &amp;Option&lt;T&gt;? · clippy · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/index.html">clippy</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Why.20lint.20on.20.26Option.3C.26T.3E.20but.20not.20.26Option.3CT.3E.3F.html">Why lint on &amp;Option&lt;&amp;T&gt; but not &amp;Option&lt;T&gt;?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="234917933"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Why%20lint%20on%20%26Option%3C%26T%3E%20but%20not%20%26Option%3CT%3E%3F/near/234917933" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Why.20lint.20on.20.26Option.3C.26T.3E.20but.20not.20.26Option.3CT.3E.3F.html#234917933">(Apr 16 2021 at 20:45)</a>:</h4>
<p>In my code, I avoid <em>any</em> usage of <code>&amp;Option&lt;_&gt;</code> as an argument, since I can always call <code>Option::as_ref</code> <strong>and</strong> it allows me to wrap a value that wasn't originally an option, but it looks like clippy only cares if the contained type is a reference. What am I missing?</p>



<a name="235835215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Why%20lint%20on%20%26Option%3C%26T%3E%20but%20not%20%26Option%3CT%3E%3F/near/235835215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Why.20lint.20on.20.26Option.3C.26T.3E.20but.20not.20.26Option.3CT.3E.3F.html#235835215">(Apr 23 2021 at 12:57)</a>:</h4>
<p>You're referring to <code>ref_option_ref</code> lint?</p>



<a name="235835298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Why%20lint%20on%20%26Option%3C%26T%3E%20but%20not%20%26Option%3CT%3E%3F/near/235835298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Why.20lint.20on.20.26Option.3C.26T.3E.20but.20not.20.26Option.3CT.3E.3F.html#235835298">(Apr 23 2021 at 12:57)</a>:</h4>
<p>Can you give an example of code that is not linted, that you think should? You may be on to something.</p>



<a name="235835568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Why%20lint%20on%20%26Option%3C%26T%3E%20but%20not%20%26Option%3CT%3E%3F/near/235835568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Why.20lint.20on.20.26Option.3C.26T.3E.20but.20not.20.26Option.3CT.3E.3F.html#235835568">(Apr 23 2021 at 12:59)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116155">Jake Goulding</span> <a href="#narrow/stream/257328-clippy/topic/Why.20lint.20on.20.26Option.3C.26T.3E.20but.20not.20.26Option.3CT.3E.3F/near/234917933">said</a>:</p>
<blockquote>
<p>In my code, I avoid <em>any</em> usage of <code>&amp;Option&lt;_&gt;</code> as an argument</p>
</blockquote>
<p>Yeah I think that makes sense. So we could have a <code>ref_option_arg</code> lint. I'm just not sure if that is justifiable to warn by default.</p>



<a name="235891986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Why%20lint%20on%20%26Option%3C%26T%3E%20but%20not%20%26Option%3CT%3E%3F/near/235891986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Why.20lint.20on.20.26Option.3C.26T.3E.20but.20not.20.26Option.3CT.3E.3F.html#235891986">(Apr 23 2021 at 19:00)</a>:</h4>
<p><span class="user-mention silent" data-user-id="360405">Cameron Steffen</span> <a href="#narrow/stream/257328-clippy/topic/Why.20lint.20on.20.26Option.3C.26T.3E.20but.20not.20.26Option.3CT.3E.3F/near/235835298">said</a>:</p>
<blockquote>
<p>Can you give an example of code that is not linted, that you think should? You may be on to something.</p>
</blockquote>
<p>Yeah, something like:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">example</span><span class="p">(</span><span class="n">_</span>: <span class="kp">&amp;</span><span class="nb">Option</span><span class="o">&lt;</span><span class="nb">String</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
</code></pre></div>
<p>I'd expect it to suggest I change it to </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">example</span><span class="p">(</span><span class="n">_</span>: <span class="nb">Option</span><span class="o">&lt;&amp;</span><span class="nb">String</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
</code></pre></div>
<p>(which then maybe should even suggest I change it to <code>Option&lt;&amp;str&gt;</code>, but that's a different point)</p>



<a name="236103773"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Why%20lint%20on%20%26Option%3C%26T%3E%20but%20not%20%26Option%3CT%3E%3F/near/236103773" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Why.20lint.20on.20.26Option.3C.26T.3E.20but.20not.20.26Option.3CT.3E.3F.html#236103773">(Apr 25 2021 at 23:59)</a>:</h4>
<p>Yep. Feel free to open a new lint issue.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>